import Toast from '@vant/weapp/toast/toast';
import Ajax from "../../../../utils/ajax"
import Util from "../../../../utils/util"
const app = getApp();
const idMap ={
  img1:'balconyUrl',
  img2:'basementUrl',
  img3:'carportUrl',
  img4:'gardenUrl',
  img5:'interlayerUrl',
  img6:'landUrl',
   
}
Component({
  options: {
    addGlobalClass: true
  }, 
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    key:0,
    imgs:{
      img1:[],
      img2:[],
      img3:[],
      img4:[],
      img5:[],
      img6:[],
      img7:[],
      img8:[],
      img9:[],
      img10:[],
      img11:[],
      img12:[],

    }
  },
  created(){
    console.log("组件进入时渲染", app.globalData.ztPicture  );
    var tmp = app.globalData.ztPicture 
    var imgs = {}
    if(tmp.balconyUrl) imgs.img1 = [{ url:tmp.balconyUrl }]
    if(tmp.basementUrl) imgs.img2 = [{ url:tmp.basementUrl }]
    if(tmp.carportUrl) imgs.img3 =  [{ url:tmp.carportUrl }]
    if(tmp.gardenUrl) imgs.img4 =  [{ url:tmp.gardenUrl }]
    if(tmp.interlayerUrl) imgs.img5 =  [{ url:tmp.interlayerUrl }]

    if(tmp.landUrl) imgs.img6 =  [{ url:tmp.landUrl }]
    if(tmp.liftUrl) imgs.img7 =  [{ url:tmp.liftUrl }]
    if(tmp.officeBuildingUrl) imgs.img8 =  [{ url:tmp.officeBuildingUrl }]
    if(tmp.parlorUrl) imgs.img9 =  [{ url:tmp.parlorUrl }]
    if(tmp.roomUrl) imgs.img10 = [{ url:tmp.roomUrl }]

    if(tmp.shopUrl) imgs.img11 =  [{ url:tmp.shopUrl }]
    if(tmp.toiletUrl) imgs.img12 =  [{ url:tmp.toiletUrl }]
    
    this.setData({   imgs  });
 }, 

  /**
   * 组件的方法列表
   */
  methods: {
    deleteImg(event){
      var id = event.currentTarget.dataset.id
      var imgs = this.data.imgs;
      imgs[id]=[]
      this.setData({ imgs })  
      app.globalData.ztPicture[idMap[id]] =  ''
    }, 
     
    afterRead(event){
      console.log(event);
      var th = this; 
      var id = event.currentTarget.dataset.id
      var imgs = this.data.imgs;
      Ajax.upload(event.detail.file,3,{
        success:function(data){
          imgs[id]=  [    { url: data.data.url} ]
          th.setData({ imgs })  
          app.globalData.ztPicture[idMap[id]] =  data.data.url
        },
      } )
      
    },
  }
}) 